//
//  SY_ClassesLeaveCell.m
//  ChatDemo-UI2.0
//
//  Created by Sylar on 2016/11/8.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "SY_ClassesLeaveCell.h"

@implementation SY_ClassesLeaveCell
{
    UIImageView *headImage;
    UILabel *leaveTitle;
    UILabel *leaveClass;
    UILabel *leaveTime;
    UILabel *detailMark;
    
    UIImageView *newImage;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        headImage = [[UIImageView alloc]initWithFrame:CGRectMake(12, 12, 38, 38)];
        headImage.layer.cornerRadius = 19;
        
        [self.contentView addSubview:headImage];
        
        
        leaveTitle = [[UILabel alloc]initWithFrame:CGRectMake(headImage.right+15, 12, 170, 16)];
        [leaveTitle setFont:[UIFont systemFontOfSize:16]];
        [leaveTitle setTextColor:colorFromHex(@"#3b3b3b")];
        [self.contentView addSubview:leaveTitle];
        
        leaveClass = [[UILabel alloc]initWithFrame:CGRectMake(headImage.right+15, leaveTitle.bottom + 10, 100, 14)];
        [leaveClass setFont:[UIFont systemFontOfSize:14]];
        [leaveClass setTextColor:colorFromHex(@"#979797")];
        [self.contentView addSubview:leaveClass];
        
        leaveTime = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH - 112, 12, 100, 12)];
        [leaveTime setFont:[UIFont systemFontOfSize:12]];
        [leaveTime setTextColor:colorFromHex(@"#979797")];
        leaveTime.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:leaveTime];
        
        detailMark = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH - 112, leaveTime.bottom + 16, 100, 14)];
        [detailMark setFont:[UIFont systemFontOfSize:14]];
        [detailMark setTextColor:colorFromHex(@"#39adff")];
        detailMark.textAlignment = NSTextAlignmentRight;
        detailMark.text = @"查看详情";
        [self.contentView addSubview:detailMark];
        
        newImage = [[UIImageView alloc]initWithFrame:CGRectMake(headImage.right + 15, 16, 7.5, 7.5)];
        [newImage setImage:[UIImage imageNamed:@"home_circlered_"]];
        newImage.hidden = YES;
        [self.contentView addSubview:newImage];
        
        
    }
    
    return self;
}

- (void)creatCell:(HomeparLeaveModel *)leaveModel {
    
    leaveTitle.text=[NSString stringWithFormat:@"%@的请假申请",leaveModel.studentname];
    
    if (leaveModel.recalltime.length > 0) {
        leaveClass.text = @"已撤销";
    }else if (leaveModel.replynum > 0) {
        leaveClass.text = @"已回复";
    }else if (leaveModel.isread == 0) {
        leaveClass.text = @"未读";
    }else if (leaveModel.isread == 1) {
        leaveClass.text = @"已读";
    }
    
    
    leaveTime.text=[Utils getDataStringWithoutSecondString:leaveModel.jointime];
    
    if (leaveModel.studentlogo.length>0) {
        if (![leaveModel.studentlogo hasPrefix:@"http"] && leaveModel.studentlogo) {
            NSString * logo = [REQUESTIMAGEURL stringByAppendingString:leaveModel.studentlogo];
            [headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        }
    }else
    {
        headImage.image=[UIImage imageNamed:@"logo_01"];
    }
    
    
    /*
    int logotype=(int)leaveModel.studentlogotype;
    NSString *nameStr=leaveModel.studentname;
    if (logotype==0) {
        headName.hidden=NO;
        if (leaveModel.studentname.length>2) {
            nameStr = [nameStr substringFromIndex:nameStr.length-2];
            headName.text=nameStr;
        }else
        {
            headName.text=nameStr;
        }
    }else {
        headName.hidden=YES;
    }
    */
    
    if (leaveModel.isread == 0) {
        newImage.hidden = NO;
        [leaveTitle setX:headImage.right + 15 +15];
        
    }else if (leaveModel.isread == 1){
        newImage.hidden = YES;
        [leaveTitle setX:headImage.right + 15];
    }
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
